feat(react-headless-components-preview): add focustrap#36123
Open
mainframev wants to merge 1 commit into
Open
Conversation
📊 Bundle size report
🤖 This report was generated against 39041d7c84a1e8cca8b74703ddef48b1a88e1a0c |
|
Pull request demo site: URL |
b78749b to
9a7ebfb
Compare
9a7ebfb to
d0ef8d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Previous Behavior
Popover had no focus trap. The surface rendered as a
<div popover="auto">and relied entirely on the browser's light-dismiss (Escape, click-outside, popover-stack peer dismissal).New Behavior
Adds a trapFocus prop on Popover that delegates modal behavior. The surface always renders as a single element; the show mode is wired in usePopover:
doesn't announce modal semantics that aren't present.
dropped so the implicit role="dialog" + aria-modal="true" apply. The cancel event is intercepted (preventDefault + close via onOpenChange) so Escape flows through the same React state path as any other
dismiss.
A single element supporting both modes means consumers flip one prop instead of swapping component variants, and there's no portal/stacking-context divergence between the two paths.
IMPORTANT NOTE:
There one notable behavioral difference compared to a custom focus trap implementation: By default with a native dialog, all elements within the same document, except the dialog and its descendants become inert, but it is scoped only to the containing document. If the dialog is rendered inside an iframe, the rest of the parent page remains interactive (focusable), which differs to v9 behaviour
Example: https://dialog-focus-trap-test.surge.sh/